package com.ecmcloud.resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ecmcloud.common.dto.Result;
import com.ecmcloud.service.ILoginService;
import com.ecmcloud.vo.UserVO;

import cn.dev33.satoken.stp.SaTokenInfo;
import lombok.SneakyThrows;

/**
 * 用户
 */
@RestController
@RequestMapping(value = {"login","api/login"})
public class LoginResource {

	@Autowired
    private ILoginService loginService;

    /**
     * 用户登录
     *
     * @param user
     * @return
     */
    @SneakyThrows
    @PostMapping("login")
    public Result<SaTokenInfo> login(@RequestBody UserVO user) {
        return loginService.login(user);
    }
    
    /**
     * 用户token自动登录
     *
     * @param token
     * @return
     */
    @SneakyThrows
    @GetMapping("loginByToken")
    public Result<SaTokenInfo> loginByToken ( String token) {
        return loginService.loginByToken(token);
    }

    /**
     * 用户退出登录
     *
     * @return
     */
    @SneakyThrows
    @PostMapping("logout")
    public Result<String> logout() {
        return loginService.logout();
    }

}
